import Cookies from "js-cookie";
import store from '@/store'
/**
 * 清除登录信息
 */
export function clearLoginInfo() {
  Cookies.remove("token");
  sessionStorage.clear();
  localStorage.clear();
  store.commit('clearLoginInfo')
}
/*
json 树根据id溯源
 * @param {*} leafId : 搜索的id
 * @param {*} nodes : json树数据
*/ 
export function findPathByLeafId(leafId, nodes, path) {
  if(path === undefined) {
    path = [];
  }
  for(var i = 0; i < nodes.length; i++) {
      var tmpPath = path.concat();
      tmpPath.push({
        path:nodes[i].path,
        name:nodes[i].name
      });
      if(leafId == nodes[i].path) {
        return tmpPath;
      }
      if(nodes[i].children) {
        var findResult = findPathByLeafId(leafId, nodes[i].children, tmpPath);
        if(findResult) {
          return findResult;
        }
      }
  }
}